/// <summary>
/// Mainmenu. Just Main menu GUI
/// </summary>
using UnityEngine;
using System.Collections;

public class CreationMenu : MonoBehaviour
{

	public Texture2D LogoGame;
	public GUISkin skin;
	public int PageState = 0;
	public GameObject[] TargetLookat;
	//public CharacterCreator characterCreator;
	//public LoadSave ls;
	public CharacterGenerator CG;
	private float delta;
	private int pageTemp;

	private bool toggle = false;
	void Start ()
	{
		delta = 1;
		
		PlayerPrefs.SetString ("landingpage", Application.loadedLevelName);
	
	}
	

	
	

	void OnGUI ()
	{
		Cursor.lockState = CursorLockMode.None;
		if (skin)
			GUI.skin = skin;

		GUI.skin.button.fontSize = 17;
		
		switch (PageState) {
			
		case 0:
			toggle =! toggle;
			//if(toggle == false)
			SetCharacterGeneratorStatus();
			if(toggle == false)
			SetLoadSaveStatus(false);
			if (GUI.Button (new Rect (Screen.width / 2 - 130, Screen.height / 2 + 80 + (-100 * delta), 260, 50), "Character Creation")) {

				//SetLoadSaveStatus(false);
				PageState = 1;
			}

			GUI.DrawTexture (new Rect (Screen.width / 2 - (LogoGame.width * 0.5f) / 2, Screen.height / 2 - 200+ (-300 * delta), LogoGame.width * 0.5f, LogoGame.height * 0.5f), LogoGame);	
	
			break;
		case 1:
			//SetCharacterGeneratorStatus();
			SetLoadSaveStatus(true);
			if (CG != null) {
				PageState = 0;
			}
			if (CG == null) {
				if (GUI.Button (new Rect (50+ (-300 * delta), 50, 160, 50), "Back")) {
					PageState = 0;

				}	
			}
			break;


		}
		GUI.skin.label.fontSize = 14;
		GUI.skin.label.alignment = TextAnchor.MiddleCenter;
		GUI.skin.label.normal.textColor = Color.white;
		GUI.Label (new Rect (0, Screen.height - 50, Screen.width, 30), "FYP - Ser Bearington - Creation Menu");
	}

	void Update ()
	{
		delta += (0-delta)/10f;
		if(pageTemp!=PageState){
			delta = 1;
			pageTemp = PageState;
		}
		if (TargetLookat.Length > 0 && PageState < TargetLookat.Length) {
			this.transform.position = Vector3.Lerp (this.transform.position, TargetLookat [PageState].transform.position, 1.0f * Time.deltaTime);
			this.transform.rotation = Quaternion.Lerp (this.transform.rotation, TargetLookat [PageState].transform.rotation, 1.0f * Time.deltaTime);	
		}
	}

	public void SetLoadSaveStatus(bool status){
		this.GetComponent<LoadSave>().enabled = status;
	}
	public void SetCharacterGeneratorStatus(){
		toggle =! toggle;
		this.GetComponent<CharacterGenerator>().enabled = toggle;
	}
}
